package com.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * 构建tree
 * @author 池豪杰
 * @date 2019年6月3日
 *
 */
@ApiModel("资源目录")
@Getter
@Setter
public class Tree<T> implements Serializable {
    /**
     */
    private static final long serialVersionUID = 8252778413727093519L;
    /**
     * 节点ID
     */
    private String id;
    /**
     * 显示节点文本
     */
    private String text;
    /**
     * 节点状态，open closed
     */
    private String state = "open";
    /**
     * 节点是否被选中 true false
     */
    private boolean checked = false;
    /**
     * 节点属性
     */
    private Map<String, Object> attributes;
    /**
     * 节点的子节点
     */
    private List<Tree<T>> childrenNode = new ArrayList<Tree<T>>();

    /**
     * 父ID
     */
    @ApiModelProperty("父资源ID")
    private String parentId;
    /**
     * 是否有父节点
     */
    private boolean isParent = false;
    /**
     * 是否有子节点
     */
    private boolean isChildren = false;



    @ApiModelProperty("资源名称")
    private String name;

    @ApiModelProperty("资源描述")
    private String comment;


    @ApiModelProperty("层级")
    private String level;

    @ApiModelProperty("接口地址")
    private String url;

    @ApiModelProperty("请求方式（GET、POST、DELETE、PUT）")
    private String method;

    @ApiModelProperty("状态：1正常0删除")
    private Integer status;

    private  Boolean isShow=true;

    public Boolean getShow() {
        return isShow;
    }

    public void setShow(Boolean show) {
        isShow = show;
    }


    public Tree(Long id, String text, String state, boolean checked,
                Map<String, Object> attributes, List<Tree<T>> children,
                boolean isParent, boolean isChildren, String parentID) {
        super();
        this.id =String.valueOf(id);
        this.text = text;
        this.state = state;
        this.checked = checked;
        this.attributes = attributes;
        this.childrenNode = children;
        this.isParent = isParent;
        this.isChildren = isChildren;
        this.parentId = parentID;
    }

    public Tree() {
        super();
    }

    public Tree(Long id, String text, String parentId) {
        super();
        this.id =String.valueOf(id);
        this.text = text;
        this.parentId = parentId;
    }

    public Tree(Long id, String text, Long parentId) {
        super();
        this.id =String.valueOf(id);
        this.text = text;
        this.parentId = parentId==null ? null : String.valueOf(parentId);
    }

    @Override
    public String toString() {

        return JSON.toJSONString(this);
    }

    public boolean isParent() {
        return isParent;
    }

    public boolean isChildren() {
        return isChildren;
    }
}